import opengraph.api.HtmlFetcher
import opengraph.api.OpenGraph
import opengraph.api.OpenGraphMeta

fun main(){
    val data = OpenGraph.builder()
        .setHtmlFetcher(object : HtmlFetcher {
            override fun fetch(url: String): String {
                return """
                    <meta property="og:title" content="The Rock" />
                    <meta property="og:title" content="The Rock2" />
                    <meta property="og:type" content="video.movie" />
                    <meta property="og:url" content="https://www.imdb.com/title/tt0117500/" />
                    <meta property="og:url:temp" content="https://www.imdb.com/title/tt0117500/" />
                    <meta property="og:image" content="https://ia.media-imdb.com/images/rock.jpg" />
                """.trimIndent()
            }
        })
        .build()
        .get("")


    require(data.find<OpenGraphMeta?>("@og").toString() == "{image = [https://ia.media-imdb.com/images/rock.jpg], title = [The Rock, The Rock2], type = [video.movie], url = {content = [https://www.imdb.com/title/tt0117500/], temp = [https://www.imdb.com/title/tt0117500/]}}")
    require(data.find<OpenGraphMeta?>("@og.title").toString() == "[The Rock, The Rock2]")
    require(data.find<List<String>?>("@og.title:").toString() == "[The Rock, The Rock2]")
    require(data.find<String?>("@og.title:1").toString() == "The Rock2")
    require(data.find<OpenGraphMeta?>("@og.type").toString() == "[video.movie]")
    require(data.find<List<String>>("@og.type:").toString() == "[video.movie]")

    require(runCatching {
        data.find<List<String>>("@og..type:")
    }.exceptionOrNull()?.message == "Path cannot be empty.")


    require(runCatching {
        data.find<List<String>>("@og.type:1:")
    }.exceptionOrNull()?.message == "Unsupported command.")


    println("Test passed.")
}